package com.zf.spring.microservice.service.netty;

import io.netty.channel.ChannelHandlerContext;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OperIntegralExecutor implements Runnable {
	private static final Logger logger = LoggerFactory
			.getLogger(OperIntegralExecutor.class);

	private Map<String, List<String>> dataRequestData;
	private ChannelHandlerContext channelHandlerContext;

	public OperIntegralExecutor(ChannelHandlerContext ctx,
			Map<String, List<String>> dataRequestData) {
		super();
		this.dataRequestData = dataRequestData;
		this.channelHandlerContext = ctx;
	}

	@Override
	public void run() {
		ResponseMessage responseMessage = null;
		try {
			// 想办法去实现你自己的业务逻辑...
			for (Entry<String, List<String>> entry : dataRequestData.entrySet()) {
				for (String val : entry.getValue()) {
					logger.warn(String.format("参数名:%s 参数值:%s", entry.getKey(),
							val));
				}
			}
			responseMessage = new ResponseMessage(true, "good,跑起來了.定制你自己的微服务吧");
		} catch (Throwable e) {
			logger.warn(e.getMessage(), e);
			responseMessage = new ResponseMessage(false, e.getMessage());
		} finally {
			ChannelUtil.writeResponseMessage(responseMessage,
					channelHandlerContext, null);
		}
	}

	public Map<String, List<String>> getDataRequestData() {
		return dataRequestData;
	}

	public void setDataRequestData(Map<String, List<String>> dataRequestData) {
		this.dataRequestData = dataRequestData;
	}

}
